package com.jinxin.platform.cdfaceacs.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @author : zhangpeng
 * @date : 2021-05-14 17:56:27
 **/
public class Md5Encrypt {

    static char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};

    /**
     * Md5加密的时候传入的参数KDC没用 (non-Javadoc)
     */
    public static String encryptPassword(String encryString) {
        String pwd = null;

        try {
            byte[] strTemp = encryString.getBytes();
            MessageDigest mdTemp = MessageDigest.getInstance("MD5");
            mdTemp.update(strTemp);
            byte[] md = mdTemp.digest();
            int j = md.length;
            char str[] = new char[j * 2];
            int k = 0;
            for (int i = 0; i < j; i++) {
                byte byte0 = md[i];
                str[k++] = hexDigits[byte0 >>> 4 & 0xf];
                str[k++] = hexDigits[byte0 & 0xf];
            }
            pwd = new String(str);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }

        return pwd;
    }

}
